/**
 * 
 */
package com.yunyike.service.impl;

import java.util.LinkedList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yunyike.mapper.CategoryMapper;
import com.yunyike.model.Category;
import com.yunyike.service.ICategoryService;
import com.yunyike.utils.mybatis.PageBean;

/**
 * @author zhengqiang.shi
 * 2016-3-31 下午5:44:01
 */
@Service("CategoryServiceImpl")
public class CategoryServiceImpl implements ICategoryService {

	@Autowired
	private CategoryMapper categoryMapper;
	
	public int addCategory(Category category) {
		return categoryMapper.insertSelective(category);
	}

	public List<Category> findAllCategory() {
//		return categoryMapper.findAllCategory();
		
		return null;
	}

	public List<Category> findCategoryByPage(PageBean<String> pageBean) {
		// 一级类目 分页
		List<Category> categoryListPage = categoryMapper
				.findCategoryListPage(pageBean);

		// 一级类目 id
		List<Integer> parentIds = new LinkedList<Integer>();

		for (Category category : categoryListPage) {
			Integer categoryId = category.getCategoryId();
			parentIds.add(categoryId);
		}

		// 获取二级类目
		List<Category> categoryByParentIds = categoryMapper
				.findCategoryByParentIds(parentIds);

		categoryListPage.addAll(categoryByParentIds);

		return categoryListPage;
	}
}
